//
//  BgetMoneyJLViewController.m
//  DistributorAB
//
//  Created by 主事丫环 on 2019/5/23.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "BgetMoneyJLViewController.h"
#import "BgetModeyTableViewCell.h"
#import "BgetmoneyModel.h"
#import "DISBproContentViewController.h"
@interface BgetMoneyJLViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *myTableView;
@property(nonatomic,strong)NSMutableArray *mydateSource;

@end

@implementation BgetMoneyJLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    self.title = _titleStr;
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    
    self.mydateSource = [NSMutableArray arrayWithCapacity:1];
    [self.myTableView reloadData];
    
    [self request];
    [self showheader];
    // Do any additional setup after loading the view.
}

-(void)showheader{
    UIView *head = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, 69)];
    head.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
    UILabel *contertLb = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, KWIDTH, 37)];
    contertLb.textAlignment = NSTextAlignmentCenter;
    contertLb.textColor = [UIColor colorWithHexString:@"#F6A533"];
    contertLb.font = FontSize(26);
    contertLb.text = [NSString stringWithFormat:@"%@(元)",_moneyStr];
    [head addSubview:contertLb];
    self.myTableView.tableHeaderView = head;
}

-(void)request{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithCapacity:1];
    param[@"type"] = _typeSYstr;
    [NetWorkTool POST:BeMyShopassetsList param:param success:^(id dic) {
        [self.mydateSource removeAllObjects];
        
        self.mydateSource = [BgetmoneyModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];

        [self.myTableView reloadData];
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
        [self.mydateSource removeAllObjects];
        [self.myTableView reloadData];
        
    } fail:^(NSError *error) {
        [self.mydateSource removeAllObjects];
        [self.myTableView reloadData];
    
    } needUser:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.mydateSource.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
      return 5;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 84;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BgetModeyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BgetModeyTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    BgetmoneyModel *model = _mydateSource[indexPath.section];
    cell.backgroundColor = [UIColor whiteColor];
    [cell refashwithModel:model];
//    if ([model.icet_id integerValue] == 1) {
//        cell.bgLB.backgroundColor = [UIColor colorWithHexString:@"#B1B0AF"];
//    } else {
//        cell.bgLB.backgroundColor = [UIColor whiteColor];
//    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    DISASYListModel *model = _mydateSource[indexPath.section];
//    DISBproContentViewController *VC= [[DISBproContentViewController alloc]init];
//    VC.urls = model.Id;
//    [self.navigationController pushViewController:VC animated:YES];
}

-(UITableView *)myTableView{
    if (!_myTableView) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kNaviHeight, KWIDTH, KHEIGHT-kNaviHeight) style:(UITableViewStylePlain)];
        _myTableView.backgroundColor = [UIColor clearColor];
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _myTableView.estimatedRowHeight = 90;
        _myTableView.rowHeight = UITableViewAutomaticDimension;
        _myTableView.tableFooterView = [UIView new];
        //        _myTableView.placeHolderView = [[KKTableViewNoDataView alloc]initWithFrame:_myTableView.bounds image:imgname(@"tableviewPlaseholder") viewClick:^{
        //            [_myTableView.mj_header beginRefreshing];
        //        }];
        
        [_myTableView registerNib:[UINib nibWithNibName:@"BgetModeyTableViewCell" bundle:nil] forCellReuseIdentifier:@"BgetModeyTableViewCell"];
        adjustInset(_myTableView);
        [self.view addSubview:_myTableView];
    }
    return _myTableView;
}

@end
